const REGEX: RegExp = /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/
/** 根据传递时间戳和类型 返回指定的时间格式
 * @param {number} val
 * @param {string} format
 * @return {string}
 */
export const formatTime = (val: number, format?: string): string => {
  format = format || 'yyyy-MM-dd hh:mm:ss'
  if (val) {
    let date = new Date(val)
    date.setHours(date.getHours() + 8)
    let iterator = date.toISOString().match(REGEX) || []
    const yy = iterator[1] || ''
    const MM = iterator[2] || ''
    const dd = iterator[3] || ''
    const hh = iterator[4] || ''
    const mm = iterator[5] || ''
    const ss = iterator[6] || ''
    if (format) {
      return format.replace('yyyy', yy).replace('yy', yy.slice(2)).replace('MM', MM).replace('dd', dd).replace('hh', hh).replace('mm', mm).replace('ss', ss)
    } else {
      return [yy, MM, dd].join('-') + ' ' + [hh, mm, ss].join(':')
    }
  } else {
    return '--'
  }
}
